import { defineStore, StoreDefinition } from 'pinia'
interface UserInfo {
  activeKey: string
 
}
export const useUserStore: any = defineStore({
  id: 'user',
  state: () => {
    return {
      activeKey: '',
      userInfo: {
        headImage: '',
        headImageThumb: '',
        nickName: '',
        phone: '',
        sex: '',
        shipId: '',
        shipName: '',
        tenantName: '',
        userId: '',
        userName: '',
        token: ''
      },
      sysUser: {},
      shipInfo: {},
      sysPermissionList: [], // PC动态路由数据
      sysPermissionMap: {}
    }
  },
  actions: {
    // 更新用户信息
    setUserInfo(data:string) {
      this.activeKey = data
    },
    setToken(payload: string) {
    },
    getUserInfo() {}
  },
  getters: {
    hasPermission() {
      return (permission: string) => {
        // @ts-ignore
        return !!this.sysPermissionMap[permission]
      }
    }
  },
  persist: {
    // 开启持久化
    enabled: true,
    H5Storage: window?.localStorage
  }
})
